package org.deadline.service.baseapp;

import java.util.List;
import org.deadline.model.baseapp.Address;
import org.deadline.repository.baseapp.AddressRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class AddressServiceImpl implements AddressService {

	@Autowired
    AddressRepository addressRepository;

	public long countAllAddresses() {
        return addressRepository.count();
    }

	public void deleteAddress(Address address) {
        addressRepository.delete(address);
    }

	public Address findAddress(Long id) {
        return addressRepository.findOne(id);
    }

	public List<Address> findAllAddresses() {
        return addressRepository.findAll();
    }

	public List<Address> findAddressEntries(int firstResult, int maxResults) {
        return addressRepository.findAll(new org.springframework.data.domain.PageRequest(firstResult / maxResults, maxResults)).getContent();
    }

	public void saveAddress(Address address) {
        addressRepository.save(address);
    }

	public Address updateAddress(Address address) {
        return addressRepository.save(address);
    }
}
